package Test;


import Model.AttendanceView;
import DB.AttendanceViewDB;
import org.junit.Assert;
import org.junit.Test;

import java.util.ArrayList;

public class AttendanceViewDBTest {
    //OK
    @Test
    public void testGetAllAttendanceView() throws Exception {
        AttendanceViewDB attendanceDB = new AttendanceViewDB();
        ArrayList<AttendanceView> attendanceList = attendanceDB.getAllAttendanceViews(false);

        if (attendanceList != null) {
            for (AttendanceView attendance : attendanceList) {
                System.out.println(attendance.getAttandanceId());
                System.out.println(attendance.getComment());
                System.out.println(attendance.isAttending());
                System.out.println(attendance.getStudentId());
                System.out.println(attendance.getSessionId());
                System.out.println(attendance.getDate());
                System.out.println(attendance.getCourseId());
                System.out.println(attendance.getName());
            }
        }

        else {
            Assert.fail("No attendances found");
        }
    }
    //OK
    @Test
    public void testGetAllAttendanceViewsBetweenDates() throws Exception {
        AttendanceViewDB attendanceDB = new AttendanceViewDB();
        ArrayList<AttendanceView> attendanceList = attendanceDB.getAllAttendanceViewsBetweenDates(false,"2013-09-02","2013-11-01");

        if (attendanceList != null) {
            for (AttendanceView attendance : attendanceList) {
                System.out.println(attendance.getAttandanceId());
                System.out.println(attendance.getComment());
                System.out.println(attendance.isAttending());
                System.out.println(attendance.getStudentId());
                System.out.println(attendance.getSessionId());
                System.out.println(attendance.getDate());
                System.out.println(attendance.getCourseId());
                System.out.println(attendance.getName());
            }
        }

        else {
            Assert.fail("No attendances found");
        }
    }
    //OK
    @Test
    public void testGetAllAttendanceViewForOneStudentById() throws Exception {
        AttendanceViewDB attendanceDB = new AttendanceViewDB();
        ArrayList<AttendanceView> attendanceList = attendanceDB.getAllAttendanceViewForOneStudentById(false,1);

        if (attendanceList != null) {
            for (AttendanceView attendance : attendanceList) {
                System.out.println(attendance.getAttandanceId());
                System.out.println(attendance.getComment());
                System.out.println(attendance.isAttending());
                System.out.println(attendance.getStudentId());
                System.out.println(attendance.getSessionId());
                System.out.println(attendance.getDate());
                System.out.println(attendance.getCourseId());
                System.out.println(attendance.getName());
            }
        }

        else {
            Assert.fail("No attendances found");
        }
    }
    //OK
    @Test
    public void testGetAllAttendanceViewByCourse() throws Exception {
        AttendanceViewDB attendanceDB = new AttendanceViewDB();
        ArrayList<AttendanceView> attendanceList = attendanceDB.getAllAttendanceViewByCourse(false,1);

        if (attendanceList != null) {
            for (AttendanceView attendance : attendanceList) {
                System.out.println(attendance.getAttandanceId());
                System.out.println(attendance.getComment());
                System.out.println(attendance.isAttending());
                System.out.println(attendance.getStudentId());
                System.out.println(attendance.getSessionId());
                System.out.println(attendance.getDate());
                System.out.println(attendance.getCourseId());
                System.out.println(attendance.getName());
            }
        }

        else {
            Assert.fail("No attendances found");
        }
    }

    //OK
    @Test
    public void testGetAllAttendanceViewByStudentAndCourse() throws Exception {
        AttendanceViewDB attendanceDB = new AttendanceViewDB();
        ArrayList<AttendanceView> attendanceList = attendanceDB.getAllAttendanceViewByStudentAndCourse(false, 1, 1);

        if (attendanceList != null) {
            for (AttendanceView attendance : attendanceList) {
                System.out.println(attendance.getAttandanceId());
                System.out.println(attendance.getComment());
                System.out.println(attendance.isAttending());
                System.out.println(attendance.getStudentId());
                System.out.println(attendance.getSessionId());
                System.out.println(attendance.getDate());
                System.out.println(attendance.getCourseId());
                System.out.println(attendance.getName());
            }
        }

        else {
            Assert.fail("No attendances found");
        }
    }
    //OK
    @Test
    public void testGetAllAttendanceViewByStudentAndCourseBetweenDates() throws Exception {
        AttendanceViewDB attendanceDB = new AttendanceViewDB();
        ArrayList<AttendanceView> attendanceList = attendanceDB.getAllAttendanceViewByStudentAndCourseBetweenDates(false, 1, 1, "2013-09-02", "2013-11-01");

        if (attendanceList != null) {
            for (AttendanceView attendance : attendanceList) {
                System.out.println(attendance.getAttandanceId());
                System.out.println(attendance.getComment());
                System.out.println(attendance.isAttending());
                System.out.println(attendance.getStudentId());
                System.out.println(attendance.getSessionId());
                System.out.println(attendance.getDate());
                System.out.println(attendance.getCourseId());
                System.out.println(attendance.getName());
            }
        }

        else {
            Assert.fail("No attendances found");
        }
    }

    //OK
    @Test
    public void testGetAllDistinctoursesByStudentId() throws Exception {
        AttendanceViewDB attendanceDB = new AttendanceViewDB();
        ArrayList<Integer> courseIds = attendanceDB.getAllDistinctCoursesByStudentId(false,1);

        if (courseIds != null) {
            for (Integer x : courseIds) {
                System.out.println(x);
            }
        }

        else {
            Assert.fail("No attendances found");
        }
    }
}
